//
//  SWAddChildReq.swift
//  ChildStory
//
//  Created by linhan on 16/9/1.
//  Copyright © 2016年 Aiya. All rights reserved.
//

import Foundation
class SWAddChildReq: SWBaseRequest
{
    var avatarURL:String?
    var screenName:String?
    var birthday:NSDate?
    var gender:SWGender?
    var role:Int?
    
    override init()
    {
        super.init()
        api = SWRequestAPI.AddChild
    }
    
    override var params:Any?
    {
        var param:[String:Any] = [:]
        
        if screenName != ""
        {
            param["nickName"] = screenName
        }
        
        if let role = role
        {
            param["relation"] = role
        }
        
        if let gender = gender
        {
            param["sex"] = gender.responseValue
        }
        
        if let birthday = birthday
        {
            param["birthday"] = birthday.formattedDate(withFormat: "yyyy-MM-dd HH:mm:ss")
        }
        
        let jsonString:String = JSONHelper.JSONEncode(param)
        trace("SWAddChildReq", jsonString)
        
        return ["childInfoJson":jsonString]
    }
    
    override func JSONToModel(_ json:JSON, JSONString:String, JSONData:Data) -> AnyObject?
    {
        trace(url, json)
        return Mapper<SWAddChildRsp>().map(JSONString: JSONString)
    }
}

class SWAddChildRsp: NSObject,Mappable
{
    var code:String?
    var data:SWAuthDataRsp?
    
    required init?(map: Map) { }
    
    // Mappable
    func mapping(map: Map) {
        code    <- map["Statu"]
        data    <- map["BaseModle"]
    }
}
